package cn.itsource.hrm.web.controller;

import cn.itsource.hrm.domain.dto.RegisterDto;
import cn.itsource.hrm.domain.dto.SendSmsCodeDto;
import cn.itsource.hrm.service.IVerifycodeService;
import cn.itsource.hrm.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
public class VerifycodeController {
    
    @Autowired
    private IVerifycodeService verifycodeService;

    /**
     * 生成图形 验证码
     * @param key
     * @return
     */
    @RequestMapping(value = "/verifycode/imageCode/{key}",method = RequestMethod.GET)
    public AjaxResult getImageCode(@PathVariable("key") String key){
       String base64 =  verifycodeService.getImageCode(key);
       return AjaxResult.me().setResultObj(base64);
    }
    
    /**
     * 发送短信 验证码
     * @param smsCodeDto
     * @return
     */
    @RequestMapping(value = "/verifycode/sendSmsCode",method = RequestMethod.POST)
    public AjaxResult getImageCode(@RequestBody @Valid SendSmsCodeDto smsCodeDto){
       verifycodeService.sendSmsCode(smsCodeDto);
       return AjaxResult.me();
    }    /**
     
     
     
     * 用户注册的验证 
     * @param registerDto
     * @return
     */
    @RequestMapping(value = "/user/register",method = RequestMethod.POST)
    public AjaxResult regist(@RequestBody @Valid RegisterDto registerDto){
       verifycodeService.regist(registerDto);
       return AjaxResult.me();
    }

    
    
}
